<!-- Phan khai bao bien cuc bo-->
<?php
$v_number = 0;
$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter=_replace_bad_char(trim($_REQUEST['hdn_filter']));
}	
if ($v_worktype_id <> "") {
	$v_worktype_id = _replace_bad_char($arr_single_worktype['PK_WORKTYPE']);	
	$v_worktype_code = _replace_bad_char($arr_single_worktype['PK_WORKTYPE']);
	$v_worktype_name = _replace_bad_char($arr_single_worktype['C_NAME']);
	$v_worktype_order = $arr_single_worktype['C_ORDER'];
	$v_worktype_status =$arr_single_worktype['C_STATUS'];
	$v_process_step_id =$arr_single_worktype['C_OCCURING_TIME'];//occuring_time
	$v_occuring_number =$arr_single_worktype['C_OCCURING_NUMBER'];
	$v_record_status_id =$arr_single_worktype['C_RECORD_STATUS'];
	$v_staff_id_list =$arr_single_worktype['C_STAFF_ID_LIST'];	
} 
if($v_staff_id_list<>""){
	$arr_worktype_update_staff = split(",",$v_staff_id_list);	
}
if (($v_worktype_id > 0) or ($v_worktype_id <> "")){
	$v_readonly = "readonly";
}else{
	$v_readonly = "";
	$v_worktype_order = _get_next_value("T_ONEGATE_WORKTYPE","C_ORDER","");
	$v_worktype_id = "";
	$v_worktype_code = "";
	$v_worktype_name = "";
	$v_worktype_status =1;
}
$v_str_worktype_checked = "";
if ($v_worktype_status==1){
	$v_str_worktype_checked="checked";
}
$v_count_recordtype = count ($arr_all_recordtype); 
$v_count_worktype_recordtpe= count($arr_all_worktype_recordtype);
$v_dis = "none";
if ($v_count_recordtype > 0){
	$v_dis = "block";
}

$v_goto_url_for_delete_file = "javascript:delete_row(document.all.tr_line_new,document.forms(0).chk_file_attach_new_id,document.forms(0).hdn_deleted_new_file_id_list);";
$v_goto_url_for_add_file = "javascript:add_row(document.all.tr_line_new," . _CONST_ARTICLE_UPDATE_DATE_MAXLENGTH .");";?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="large_title">
		<td><?php echo CONST_WORKTYPE_UPDATE_TITLE; ?></td>
	</tr>
</table>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" border="0">
	<col width="24%"><col width="10%"><col width="25%"><col width="40%">
	<tr>
		<form action="index.php" name="f_dsp_single_status" enctype="multipart/form-data" method="post">
		<input type="hidden" name="fuseaction" value="UPDATE_WORKTYPE_SPEC" >
		<input type="hidden" name="hdn_worktype_id" value="<?php echo $v_worktype_id;?>" >
		<input type="hidden" name="hdn_item_id" value="<?php echo $v_worktype_id;?>" >
		<input type="hidden" name="hdn_worktype_status" value="<?php echo $v_worktype_status;?>" >
		<input type="hidden" name="hdn_process_step" value="<?php echo $v_process_step_id; ?>">
		<input type="hidden" name="hdn_record_status" value="<?php echo $v_record_status_id; ?>"> 
		<input type="hidden" name="hdn_occuring_number" value="<?php echo $v_occuring_number; ?>"> 
		<input type="hidden" name="hdn_worktype_status" value="<?php echo $v_worktype_status;?>"> 
		<input type="hidden" name="hdn_recordtype_id_list" value="">
		<input type="hidden" name="hdn_number_id_list" value="">					<!-- nieuvv-->
		<input type="hidden" name="hdn_deleted_exist_file_id_list" value="">		
		<input type="hidden" name="hdn_deleted_new_file_id_list" value="">
		<input type="hidden" name="hdn_filter"  value="<?php echo $v_filter; ?>">
		<input type="hidden" name="hdn_staff_id_list"  value="">
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_WORKTYPE_CODE_LABEL; ?><small class="normal_starmark">*</small></td>
		<td  colspan="3"><input  name="txt_code" type="text" <?php echo $v_readonly; ?> class="normal_textbox" style="width:60%" value="<?php echo $v_worktype_code; ?>" maxlength="<?php echo CONST_WORKTYPE_CODE_MAXLENGTH; ?>" message="<?php echo CONST_WORKTYPE_CODE_MESSAGE;?>" optional="<?php echo CONST_WORKTYPE_CODE_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_WORKTYPE_NAME_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td  colspan="3"><input name="txt_name" type="text"  class="normal_textbox" style="width:100%" value="<?php echo $v_worktype_name; ?>" maxlength="<?php echo CONST_WORKTYPE_NAME_MAXLENGTH;?>" message="<?php echo CONST_WORKTYPE_NAME_MESSAGE;?>" optional="<?php echo CONST_WORKTYPE_NAME_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_ORDER_LABEL; ?></td>
	  <td><input name="txt_order" type="text" class="short_number_textbox" value="<?php echo $v_worktype_order; ?>" maxlength="<?php echo CONST_WORKTYPE_ORDER_MAXLENGTH;?>" message="<?php echo CONST_WORKTYPE_ORDER_MESSAGE;?>" optional="<?php echo CONST_WORKTYPE_ORDER_OPTIONAL;?>" isnumeric="<?php echo CONST_WORKTYPE_ORDER_ISNUMERIC; ?>" min="<?php echo CONST_WORKTYPE_ORDER_MIN; ?>" max="<?php echo CONST_WORKTYPE_ORDER_MAX; ?>" onKeyDown="change_focus(document.forms(0),this)"></td>
		<td><input type="checkbox" name="chk_status" <?php echo $v_enable;?> class="normal_checkbox" <?php echo $v_str_worktype_checked;?> onClick="btn_single_checkbox_onclick(document.forms(0).chk_status,document.forms(0).hdn_worktype_status)" onKeyDown="change_focus(document.forms(0),this)"> <?php echo _CONST_STATUS_COLUMN_ACTIVE_VALUE;?></td>
	</tr>
	<tr>
		<td colspan="5" ><hr color="#66CCFF" size="1"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_PROCESS_STEP_LABEL;?></td>
		<td colspan="3">
			<select class="normal_selectbox" name="sel_process_step" style="width:100%"  onChange="sel_onclick(this,document.forms(0).hdn_process_step);">
	            <?php echo _generate_select_option($arr_record_process_step,'0','0','1', $v_process_step_id);?>
        	</select>
		</td>
	</tr>	
	<!-- tuyenntt mo hien thi field nay-->
	<tr style="display:<?php echo $v_dis;?>">
		<td class="normal_label" colspan="2"><?php echo CONST_STATUS_LABEL;?></td>
		<td colspan="3">
			<select class="normal_selectbox" name="sel_status" style="width:100%"  onChange="sel_onclick(this,document.forms(0).hdn_record_status);">
	            <?php echo _generate_select_option($arr_record_status,'0','0','1', $v_record_status_id);?>
        	</select>
		</td>
	</tr>
	<tr>
		<td class="normal_label" colspan="3"><?php echo CONST_OCCURING_NUMBER_LABEL;?></td>
		<td>
			<select class="normal_selectbox" name="sel_occuring_number" style="width:100%"  onChange="sel_onclick(this,document.forms(0).hdn_occuring_number);">
	            <?php echo _generate_select_option($arr_work_occuring_time,'0','0','1', $v_occuring_number);?>
        	</select>
		</td>
	</tr>
	<tr style="display:<?php echo $v_dis;?> ">
		<td class="normal_label" colspan="3"><?php echo CONST_RECORDTYPE_LABEL;?></td>
	</tr>
	<!-- loai ho so -->
	<!-- modified by tuyenntt -->
	<tr style="display:<?php echo $v_dis;?> ">
		<td colspan="5">
		<DIV STYLE="overflow: auto; height:120pt; padding-left:5px;margin:0px">
				<table class="list_table2"  width="100%" cellpadding="0" cellspacing="0">
					<col width="2%"><col width="50%"><col width="48%"><?php
					for ($k=0;$k<$v_count_recordtype;$k++) {
						$v_item_url_onclick = "change_item_checked(this,'tr_recordtype','rad_recordtype')";					
						$v_recordtype_id = $arr_all_recordtype[$k]['0'];
						$v_recordtype_name = $arr_all_recordtype[$k]['1'];
						//echo $arr_all_recordtype[$k]['3'];
						if ($v_current_style_name == "odd_row"){
							$v_current_style_name = "round_row";
						}else{
							$v_current_style_name = "odd_row";
						}
						$v_item_checked = "";
						for ($j=0; $j<$v_count_worktype_recordtpe; $j++)
							if (($arr_all_worktype_recordtype[$j]['1']== $v_worktype_id) and ($arr_all_worktype_recordtype[$j]['2']==$v_recordtype_id)){
								$v_item_checked = "checked";
								break;
						}?>
						
						<tr id="tr_recordtype" value="<?php echo $v_recordtype_id;?>" checked="<?php echo $v_item_checked;?>" class="<?php echo $v_current_style_name;?>">
							<td ><input type="checkbox" name="chk_recordtype" value="<?php echo $v_recordtype_id;?>" <?php echo $v_item_checked;?>  onClick="<?php echo $v_item_url_onclick;?>">
							</td>
							<td colspan="5 "><?php echo $v_recordtype_name;?></td>
							<!-- modified by tuyenntt && nieuvv-->
							<td colspan="5 "><?php echo _CONST_NUMBER_DAY_HANDLE_LABEL?>:
								<input type="text" name="v_number" class="normal_textbox" style="width:50%"  value="<?php
								if($arr_all_worktype_recordtype[$j]['3'] == ''){echo '0';}	
								else {echo $arr_all_worktype_recordtype[$j]['3'];}
													
					?>"/>
							</td> 
						</tr><?php					
					}?>	
						
				</table>
		</DIV>
		</td>
	</tr>
	<!-- ket thuc loai ho so -->
	<tr style="display:<?php echo $v_dis;?> ">
		<td class="normal_label" colspan="2" align="left">
			<input type="radio" name="rad_selectall" value="0" onClick="checkall(document.forms(0).chk_recordtype);"><?php echo CONST_RECORD_SELECT_ALL_LABEL?>
			<input type="radio" name="rad_selectall" value="1" checked onClick="decheckall(document.forms(0).chk_recordtype);"><?php echo CONST_RECORD_DESELECT_ALL_LABEL?>
		</td>
		<td class="normal_label" colspan="2" align="left">
			<input type="radio" id="rad_recordtype" value="0" checked onClick="show_row_all('rad_recordtype','tr_recordtype');"><?php echo CONST_RECORD_ALL_ITEM_DISPLAY;?>
			<input type="radio" id="rad_recordtype" value="1" onClick="show_row_selected('rad_recordtype','tr_recordtype');"><?php echo CONST_RECORD_ITEM_DISPLAY;?>
		</td>
	</tr>
	<tr><td colspan="4" ><hr color="#66CCFF" size="1"></td></tr>	
	<tr><td class="normal_label" colspan="4"><?php echo CONST_WORKTYPE_UPDATE_STAFF_TITLE;?></td></tr>
	<tr>
		<td colspan="4">
			<!-- Bat cac phim: F12=false; Insert=true; Delete=true, ESC=false; Enter=false -->
			<div id="hotkey" onKeyDown="javascript:process_hot_key(false,true,true,false,false);">
			<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
				<col width="5%"><col width="5%"><col width="90%">
				<tr class="header">
					<td></td>
					<td>#</td>	
					<td><?php echo CONST_ENDUSER_NAME_LABEL; ?></td>
				</tr>
			</table>
			<div style="overflow: auto; width: 100%; height:<?php echo CONST_HEIGHT_OF_LIST?>;padding-left:0px;margin:0px">
			<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
				<col width="5%"><col width="5%"><col width="90%"><?php
				$arr_all_user = get_all_enduser($_SESSION['arr_all_enduser']);				
				$v_count = sizeof($arr_all_user);
				if ($v_count >0){
					$i = 0;
					$v_old_unit_level_one_name = "";
					while($i < $v_count) {
						$v_item_id = $arr_all_user[$i][0];
						$v_item_name = $arr_all_user[$i][1];
						$v_unit_level_one_id = $arr_all_user[$i][2];
						$v_unit_level_one_name = $arr_all_user[$i][3];
						$v_unit_name = $arr_all_user[$i][4];
						$v_count_update_worktype_staff = sizeof($arr_worktype_update_staff);
						$v_checked = "";
						for($v_index = 0;$v_index < $v_count_update_worktype_staff;$v_index++)
							if($arr_worktype_update_staff[$v_index] == $v_item_id){
								$v_checked = "checked";
							}
						$v_img_url_onclick = "show_enduser_on_unit(this)";
						$v_chk_modul_id_onclick = "select_all_enduser_on_unit(this,document.all.chk_staff_id_list)";
						$v_chk_enduser_id_onclick = "set_value_checked_checkbox_unit(this,document.all.chk_staff_id_list,document.all.chk_unit_id)";
						if ($v_current_style_name == "odd_row"){
							$v_current_style_name = "round_row";
						}else{
							$v_current_style_name = "odd_row";
						}
						if ($v_unit_level_one_name != $v_old_unit_level_one_name){?>	
							<tr class="midle_row">
								<td align="center">
									<input type="checkbox" name="chk_unit_id" value="<?php echo $v_unit_level_one_id; ?>" onClick="<?php echo $v_chk_modul_id_onclick;?>">
								</td>
								<td align="center">
									<img id="img_unit" src="<?php echo $_ISA_IMAGE_URL_PATH;?>open.gif" class="normal_image" unit="<?php echo $v_unit_level_one_id;?>" status="on" onClick="<?php echo $v_img_url_onclick;?>">
								</td>
								<td align="left" colspan="10">
									<a name="<?php echo $v_unit_level_one_id;?>"><?php echo $v_unit_level_one_name; ?>&nbsp;</a>
								</td>
							</tr><?php 
							$v_old_unit_level_one_name = $v_unit_level_one_name;
						}?>
						<tr id="tr_enduser" value="<?php echo $v_item_id;?>"  unit="<?php echo $v_unit_level_one_id;?>" class="<?php echo $v_current_style_name; ?>">
							<td>&nbsp;&nbsp;</td>
							<td align="center">
								<input type="checkbox" <?php echo $v_checked?> name="chk_staff_id_list" value="<?php echo $v_item_id; ?>" unit_id="<?php echo $v_unit_level_one_id;?>" onClick="<?php echo $v_chk_enduser_id_onclick;?>">
							</td>				
							<td align="left">
								<?php echo $v_item_name; ?>&nbsp;
							</td>
						</tr><?php 
						$i++;
					}	
				}
				if ($v_current_style_name == "odd_row"){
					$v_next_style_name = "round_row";
				}else{
					$v_next_style_name = "odd_row";
				}
				echo _add_empty_row($v_count,_CONST_NUMBER_OF_ROW_PER_LIST,$v_current_style_name,$v_next_style_name,3);?>
			</table>
			</div>	
			<!--Table chua cac nut Show_all va Hide_all-->
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr><?php 
					if ($v_count>0){?>
					<td class="small_radiobutton" colspan="10" width="50%" height="25">
						<input type="radio" id="rad_show_enduser" value="1" checked onClick="show_or_hide_all_enduser('SHOW_ALL',document.all.tr_enduser,document.all.img_unit,document.all.rad_show_enduser)" ><?php echo CONST_SHOW_ALL_ENDUSER;?>
					</td>
					<td class="small_radiobutton" colspan="10" width="50%" height="25">
						<input type="radio" id="rad_show_enduser" value="2" onClick="show_or_hide_all_enduser('HIDE_ALL',document.all.tr_enduser,document.all.img_unit,document.all.rad_show_enduser)"><?php echo CONST_HIDE_ALL_ENDUSER;?>
					</td><?php
					}else{?>
						<td>&nbsp;</td>
					<?php
					}?>
				</tr>
			</table>						
		</td>	
	</tr>	
	<tr><td colspan="4" ><hr color="#66CCFF" size="1"></td></tr>		
	<tr><td class="normal_label"><?php echo _CONST_WORKTYPE_ATTACH_FILE;?></td></tr>
	<tr>	
		<td colspan="2">&nbsp;</td>
      	<td colspan="14" >
		<!--Bang chua cac file dinh kem-->
			<table width="70%" cellpadding="0" cellspacing="0">
				<col width="5%"><col width="95%">
				<!--Vong lap hien thi cac file da dinh kem van ban--><?
				if(isset($arr_all_file)){
					$v_count_file = sizeof($arr_all_file);
				}else{
					$v_count_file = 0;
				}	

				if ((trim($v_worktype_id)<>"")&&($v_count_file>0)) {
					// Goi thu tuc xu ly khi xoa cac file da co
					$v_goto_url_for_delete_file = $v_goto_url_for_delete_file . "delete_row(document.all.tr_line_exist,document.forms(0).chk_file_attach_exist_id,document.forms(0).hdn_deleted_exist_file_id_list);";
					for ($i=0; $i<$v_count_file; $i++) {
						$v_file_id = $arr_all_file[$i]['PK_WORKTYPE_FILE'];
						$v_file_name = $arr_all_file[$i]['C_FILE_NAME']; 
						if(_is_sqlserver()){
							$v_file_url = trim(_CONST_UPLOAD_IMAGE_URL_PATH_VIEW). $v_file_name;
							$v_goto_url = "javascript:filename_onclick('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_file_id) . ",'" . $v_file_url ."');" ;
							$target = "";
						}?>
						<tr id="tr_line_exist">
							<td >
								 <input type="checkbox" name="chk_file_attach_exist_id" value="<? echo $v_file_id; ?>">
							</td>
							<td >
								<a href="<? echo $v_goto_url; ?>" class="normal_link" <? echo $target;?>><? echo $v_file_name;?></a>
							</td>
						</tr><?
					}
				}
//				<!--Vong lap hien thi cac file dinh kem se them vao van ban-->
				for($v_index=0; $v_index<_CONST_MAX_NUMBER_ATTACH_FILE; $v_index++){					
					if ($v_index<=1 ){ 
						$v_str_show="block";
					}else{
						$v_str_show="none";
					}?>
					<tr id="tr_line_new" style="display:<? echo $v_str_show;?>;">
						<td>
						   <input type="checkbox" name="chk_file_attach_new_id" value="<? echo $v_index; ?>">
						</td>
						<td>
							<input type="file" name="file_attach_worktype<? echo $v_index;?>" size="60" class="small_textbox" optional="true">
						</td>
					</tr><?
				}?>
				<!--Cac Button Them va Xoa file dinh kem van ban-->
				<tr align="center">
					<td colspan="2">
						<a href="<? echo $v_goto_url_for_add_file;?>" class="small_link" ><? echo _CONST_ADD_BUTTON;?></a> &nbsp;
						<a href="<? echo $v_goto_url_for_delete_file;?>" class="small_link"><? echo _CONST_DELETE_BUTTON;?></a>
					</td>
				</tr>
			</table>						
		</td>
	</tr>	
</table>
	
<!--bang chua cac button-->
<table width="100%" >
	<tr>
		<td align="center" width="100%" height="40" valign="bottom"><?php
                           // nieuvv
			if ($v_is_granted_update){?>
				<input type="button" name="btn_save"  class="normal_button" value="<?php echo _CONST_SAVE_BUTTON;?>" onClick="save_hidden_list_item_id(document.forms(0).hdn_staff_id_list,document.forms(0).chk_staff_id_list);btn_save_worktype_recordtype_onclick(document.forms(0).chk_recordtype,document.forms(0).v_number,document.forms(0).hdn_recordtype_id_list,document.forms(0).hdn_number_id_list,'UPDATE_WORKTYPE_SPEC');" onKeyDown="change_focus(document.forms(0),this)"><?php
			}
                            // the end nieuvv
                          ?>
				<input type="button" name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('<?php echo $_GO_BACK?>')" onKeyDown="change_focus(document.forms(0),this)">	
		</td>
	</tr>
</table>					
</div>
</form>

<script language="JavaScript">
	set_focus(document.forms(0));
	<?	if ($v_worktype_id != "") { ?>
		document.forms(0).rad_recordtype[1].click();
	<? }?>	
</script>
